// pages/regindex/regindex.js
var app=getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    lxClazz:[{
      id:'1',
      lxClazzName:'2',
      lxClazzPeopleNum:'3',
      lxTeacher:'4',
      lxTeacherName:'5',
    }],
    dialogShow: false,
    lxClazzName:"",
    className:'',
    studentName:"",
    studentNumber:'',
    studentNumberTwo:'',
    sendNumBtn:false,
    errorMsg:'',
  },
  openConfirm: function () {  //打开弹窗
    this.setData({
        dialogShow: true
    })
},
  getAllClazz(){  //获取班级信息
    var that =this
    wx.request({
      url: app.globalData.serverUrl+'/daka/clazz/index',
      method: 'POST',
      data:{
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success(res){
        console.log(res)
        if(res.data.state=200){
          
          that.data.lxClazz=res.data.data;
        }else{
          that.data.lxClazz='暂无数据'
        }
          console.log("this.lxClazz",that.data.lxClazz)
          that.setData({
            lxClazz:res.data.data
          })
      }
    })
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail);
    this.setData({
      dialogShow:false,
      lxClazzName:e.detail.value
    })
    console.log('radio发生change事件，携带value值为： this.data.lxClazzId', this.data.lxClazzName);
    
},
  getName:function(e){
    this.setData({
      studentName:e.detail.value
    })
  },
  getNumber:function(e){
    this.setData({
      studentNumber:e.detail.value,
    })
    
  },
  getNumberTwo:function(e){
    this.setData({
      studentNumberTwo:e.detail.value,
    })
  },
  sendNum:function(){
    var that=this
    var appData=app.globalData
    var studentNumber=this.data.studentNumber;
    var studentNumberTwo=this.data.studentNumberTwo;
    var studentName=this.data.studentName
    if(studentNumber!=null&&studentNumber!=''&&studentNumber==studentNumberTwo&&studentName!=null&&studentName!=''){
      appData.UserWechat.lxUserNumber=studentNumber;
      appData.UserWechat.lxUsername=studentName;
      this.setData({
        sendNumBtn:true
      })
    wx.request({
      url: app.globalData.serverUrl+'/daka/userwechat/saveStudent',
      method: 'POST',
      data:{
        lxUserNumber:appData.UserWechat.lxUserNumber,
        lxUsername:appData.UserWechat.lxUsername,
        lxOpenid:appData.UserWechat.lxOpenid

      },
      header: {
        'Content-Type': 'application/json'
      },
      success(res){
        console.log("app.globalData.UserWechat",app.globalData.UserWechat);
        console.log("/daka/userwechat/saveStudent",res)
        //if(res.data){
          if(res.data.state==200){
            wx.redirectTo({
            url: '/pages/load/load'
          })
        }else{
          
          wx.redirectTo({
            url: '/pages/error/error?errorMsg='+res.data.message,
          })
        }
      }
    })
  }else{
  wx.showToast({
    title:'赶快检查检查学号和姓名！！👻   👻   👻',
    icon:'none'
  })
  }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     wx.setNavigationBarTitle({
      title: '绑定学号'
    })
    this.getAllClazz();
  },
 

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})